//
//  HHApplyServiceViewController.m
//  HHBroker
//
//  Created by He Wei on 9/20/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "HHApplyServiceViewController.h"
#import "HHLoginViewController.h"
#import "HHWebViewController.h"

@interface HHApplyServiceViewController ()

@property (nonatomic, strong) UIButton *appleButton;
@property (nonatomic, strong) UIButton *checkBoxButton;
@property (nonatomic, strong) UILabel *privacyLabel;
@property (nonatomic, strong) UIButton *privacyButton;
@property (nonatomic, strong) UIView *successfulView;
@property (nonatomic, strong) UIView *statusView;


@end

@implementation HHApplyServiceViewController
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Life Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.successfulView];
    [self.view addSubview:self.statusView];
    [self.view addSubview:self.appleButton];
    
}


#pragma Event
- (void)appleButtonClicked:(UIButton *)button
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    //检查是否同意协议
    if (!self.checkBoxButton.selected) {
        alertView.message = @"您必须同意《红娘经纪人协议》才可继续";
        [alertView show];
        return;
    }
    HHLoginViewController *login = [[HHLoginViewController alloc] init];
    
    [self.navigationController pushViewController:login animated:YES];
    
    
}

- (void)userPropertyButtonClick:(UIButton *)sender
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"file_matchMakerPrivacy" ofType:@"txt"];
    HHWebViewController *webVC = [[HHWebViewController alloc] init];
    webVC.fileString = path;
    webVC.title = @"红娘经纪人协议";
    [self.navigationController pushViewController:webVC animated:YES];

}

- (void)changeCheckStatus:(UIButton *)sender
{
    if (sender.selected) {
        sender.selected = NO;
    } else {
        sender.selected = YES;
    }

}

#pragma mark - Setter && Getter
- (UIView *)successfulView
{
    if (_successfulView == nil) {
        _successfulView = [[UIView alloc] initWithFrame:CGRectMake((self.view.width-109)/2.0+2, 64+49, 109, 90+10+12)];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 0, _successfulView.width, 90)];
        imageView.image = [UIImage imageNamed:@"img_duihao"];
        [_successfulView addSubview:imageView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView.bottom+10, _successfulView.width, 12)];
        label.font = [UIFont systemFontOfSize:12];
        label.text = @"注册成功";
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = UIColorFromRGB(0xff8840);
        [_successfulView addSubview:label];
    }
    return _successfulView;

}

- (UIButton *)appleButton
{
    if (_appleButton == nil) {
        _appleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _appleButton.frame = CGRectMake(15, self.statusView.bottom+10, self.view.width-30, 44);
        [_appleButton setTitle:@"登陆" forState:UIControlStateNormal];
        [_appleButton setBackgroundImage:[UIImage imageNamed:@"button_denglu_normal"] forState:UIControlStateNormal];
        [_appleButton setBackgroundImage:[UIImage imageNamed:@"button_denglu_press"] forState:UIControlStateHighlighted];
        [_appleButton addTarget:self action:@selector(appleButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _appleButton;
}

- (UIView *)statusView
{
    if (_statusView == nil) {
        _statusView = [[UIView alloc] initWithFrame:CGRectMake(0, self.successfulView.bottom+30, self.view.width, 25)];
        [_statusView addSubview:self.checkBoxButton];
        [_statusView addSubview:self.privacyLabel];
        [_statusView addSubview:self.privacyButton];
        
    }
    return _statusView;
}

- (UIButton *)checkBoxButton
{
    if (_checkBoxButton == nil) {
        _checkBoxButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _checkBoxButton.frame = CGRectMake(10, 0, 25, 25);
        [_checkBoxButton setImage:[UIImage imageNamed:@"button_duihao_press"] forState:UIControlStateSelected];
        [_checkBoxButton setImage:[UIImage imageNamed:@"button_duihao_normal"] forState:UIControlStateNormal];
        _checkBoxButton.selected = YES;
        [_checkBoxButton addTarget:self action:@selector(changeCheckStatus:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _checkBoxButton;
}

- (UILabel *)privacyLabel
{
    if (_privacyLabel == nil) {
        _privacyLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.checkBoxButton.right, 0, 85, 25)];
        _privacyLabel.text = @"我已阅读并同意";
        _privacyLabel.font = [UIFont systemFontOfSize:12];
        _privacyLabel.textColor = UIColorFromRGB(0x3b3b3b);
    }
    return _privacyLabel;
}

- (UIButton *)privacyButton
{
    if (_privacyButton == nil) {
        _privacyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _privacyButton.frame = CGRectMake(self.privacyLabel.right, 0, 180, 25);
        _privacyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_privacyButton setTitle:@"《红娘经纪人协议》" forState:UIControlStateNormal];
        _privacyButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_privacyButton setTitleColor:UIColorFromRGB(0xff6a6a) forState:UIControlStateNormal];
        [_privacyButton addTarget:self action:@selector(userPropertyButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _privacyButton;
}

@end
